package com.ruoyi.lm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmSerinfocase;
import com.ruoyi.lm.service.ILmSerinfocaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务案例Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/serinfocase")
public class LmSerinfocaseController extends BaseController
{
    private String prefix = "lm/serinfocase";

    @Autowired
    private ILmSerinfocaseService lmSerinfocaseService;

    @RequiresPermissions("lm:serinfocase:view")
    @GetMapping()
    public String serinfocase()
    {
        return prefix + "/serinfocase";
    }

    /**
     * 查询服务案例列表
     */
    @RequiresPermissions("lm:serinfocase:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmSerinfocase lmSerinfocase)
    {
        startPage();
        List<LmSerinfocase> list = lmSerinfocaseService.selectLmSerinfocaseList(lmSerinfocase);
        return getDataTable(list);
    }

    /**
     * 导出服务案例列表
     */
    @RequiresPermissions("lm:serinfocase:export")
    @Log(title = "服务案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmSerinfocase lmSerinfocase)
    {
        List<LmSerinfocase> list = lmSerinfocaseService.selectLmSerinfocaseList(lmSerinfocase);
        ExcelUtil<LmSerinfocase> util = new ExcelUtil<LmSerinfocase>(LmSerinfocase.class);
        return util.exportExcel(list, "serinfocase");
    }

    /**
     * 新增服务案例
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务案例
     */
    @RequiresPermissions("lm:serinfocase:add")
    @Log(title = "服务案例", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmSerinfocase lmSerinfocase)
    {
        return toAjax(lmSerinfocaseService.insertLmSerinfocase(lmSerinfocase));
    }

    /**
     * 修改服务案例
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmSerinfocase lmSerinfocase = lmSerinfocaseService.selectLmSerinfocaseById(id);
        mmap.put("lmSerinfocase", lmSerinfocase);
        return prefix + "/edit";
    }

    /**
     * 修改服务案例
     */
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") String id, ModelMap mmap)
    {
        LmSerinfocase lmSerinfocase = lmSerinfocaseService.selectLmSerinfocaseById(id);
        mmap.put("lmSerinfocase", lmSerinfocase);
        return prefix + "/view";
    }

    /**
     * 修改保存服务案例
     */
    @RequiresPermissions("lm:serinfocase:edit")
    @Log(title = "服务案例", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmSerinfocase lmSerinfocase)
    {
        return toAjax(lmSerinfocaseService.updateLmSerinfocase(lmSerinfocase));
    }

    /**
     * 删除服务案例
     */
    @RequiresPermissions("lm:serinfocase:remove")
    @Log(title = "服务案例", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmSerinfocaseService.deleteLmSerinfocaseByIds(ids));
    }
}
